<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JS静态分页程序</title>
</head>
<body>
<div>内容1</div>
<div>内容2</div>
<div>内容3</div>
<div>内容4</div>
<div>内容5</div>
<div>内容6</div>
<div>内容7</div>
<div>内容8</div>
<div>内容9</div>
<div>内容10</div>
<input type=button value=上一页 onclick="aa(-1)">
<input type=button value=下一页 onclick="aa(1)">
</body>
<script>
    var a = document.getElementsByTagName("div");
    var n=1;//当前页

    function aa(x)
    {
        var p = 3;
        n=n+x;
        if(n<=0)
            n=1;
        else if(n>parseInt(a.length/p))
            n=a.length/p!=0?parseInt(a.length/p)+1:parseInt(a.length/p);
        for (var i=0; i<a.length; i++)
        {
            a[i].style.display="none";
            if(i<(n*p) && i>=(n-1)*p)
                a[i].style.display="";
        }
    }
    window.onload=function(){aa(0)}
</script>
</html>
